package com.atguigu.gulimall.ware.config;

import com.atguigu.common.utils.MyMetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author: 爱学Java 不想秃头的 KK
 * @date: 2023/10/25 14:54
 * @version: 1.0
 * @Created with IntelliJ IDEA.
 * @Description:
 */



@Configuration
@EnableTransactionManagement //开启事务
@MapperScan("com.atguigu.gulimall.ware.dao")
public class MybatisConfig {

    /**
     * 添加分页插件
     * @return
     */
    @Bean
    public PaginationInterceptor mybatisPlusInterceptor() {
        PaginationInterceptor interceptor = new PaginationInterceptor();
        //设置请求的页面大于最大页后的操作，true调回到首页，false继续请求，默认false
        interceptor.setOverflow(true);
        //设置最大单页限制数量，默认500条，-1不收限制
        interceptor.setLimit(1000L);
        //interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); 如果有多数据源可以不配具体类型 否则都建议配上具体的DbType
        return interceptor;
    }


    /**
     * 自动填充和修改字段
     * @return
     */
    @Bean
    public MyMetaObjectHandler myMetaObjectHandler() {
        return new MyMetaObjectHandler();
    }
}
